package com.itheima.job.test04;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class TCPClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",12345);

        OutputStream os = socket.getOutputStream();
        InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
        Scanner sc = new Scanner(System.in);
        while (true){

            String s = sc.next();
            bw.write(s);
            bw.newLine();
            bw.flush();
            //socket.shutdownOutput();
            if ("exit".equals(s)){
                break;
            }

            String line;
            while ((line = br.readLine())!=null){
                System.out.println(line);
            }
        }
        bw.close();
        br.close();
        socket.close();
    }
}
